package com.bestom.bestoma10demo;

import android.content.Context;
import android.media.AudioManager;

public class Audio {

    private AudioManager mAudioManager;
    private static Audio mInstance;

    private Audio(Context context){
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    }

    public synchronized static Audio getInstance(Context context){
        if(mInstance == null){
            mInstance = new Audio(context);
        }
        return mInstance;
    }

    /**
     * Here I only write the volume adjustment of multimedia and call, the other is just different parameters, can imitate write
     * the first parameters (streamType) have :
     * 1. STREAM_ALARM (warning tone)
     * 2. STREAM_MUSIC (Music volume is multimedia volume)
     * 3. STREAM_NOTIFICATION (Status bar Notification at the top of the window)
     * 4. STREAM_RING (the tinkle of bells)
     * 5. STREAM_SYSTEM (system)
     * 6. STREAM_VOICE_CALL (call)
     * 7. STREAM_DTMF (dual tone multiple frequency)
     */
    public void setMediaVolume(int volume){
        //音量类型
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                volume, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
    }


    public void setCallVolume(int volume){
        //设置通话音量
        mAudioManager.setStreamVolume( AudioManager.STREAM_VOICE_CALL,
                volume, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
    }

}
